/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hit.core;

import hit.core.HomeInventoryTracker;
import hit.core.StorageUnit;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

public class HomeInventoryTrackerTest {

	private HomeInventoryTracker HIT;
	private StorageUnit su1, su2;
	
    public HomeInventoryTrackerTest() {
    }

    @BeforeClass
    public static void setUpClass() {
    }

    @AfterClass
    public static void tearDownClass() {
    }

    @Before
    public void setUp() {
		HIT = HomeInventoryTracker.GetEmptyInstance();
		su1 = new StorageUnit("Storage Unit 1");
		su2 = new StorageUnit("");
    }

    @After
    public void tearDown() {
    }

	@Test
	public void testInstance() {
		HIT = HomeInventoryTracker.Instance();
		assertEquals(HIT, HomeInventoryTracker.Instance());
	}

	@Test
	public void testAddStorageUnit() {
		try{
			HIT.AddStorageUnit(su1);
		}
		catch (IllegalArgumentException e){
			fail("Unable to add valid storage unit.");
		}
		
		try{
			HIT.AddStorageUnit(su2);
			fail("Incorrectly able to add invalid storage unit");
		}
		catch (IllegalArgumentException e){}
	}

	@Test
	public void testCanRemoveStorageUnit() {
		assertFalse("Can remove a storage unit that isn't in storageUnits.", 
				HIT.CanRemoveStorageUnit(su1));
		HIT.AddStorageUnit(su1);
		assertTrue("You ought to be able to delete Storage Unit 1", 
				HIT.CanRemoveStorageUnit(su1));
	}

	@Test
	public void testRemoveStorageUnit() {
		try{
			HIT.RemoveStorageUnit(su1);
			fail("Incorrectly removes storage unit that isn't part of storageUnits.");
		}
		catch (IllegalArgumentException e){}
		
		HIT.AddStorageUnit(su1);
		try{
			HIT.RemoveStorageUnit(su1);
		}
		catch (IllegalArgumentException e){
			fail("Unable to remove valid storage unit.");
		}
	}

	@Test
	public void testGetStorageUnit_String() {
		
		assertNull("Found non-existant storage unit.", HIT.GetStorageUnit("Storage Unit 1"));
		
		HIT.AddStorageUnit(su1);
		
		assertEquals("Couldn't find existing file HIT.", su1, HIT.GetStorageUnit("Storage Unit 1"));
	}
}